import asyncio
import aioredis
from django.conf import settings

_redis_pool = None
_lock = asyncio.Lock()  # 确保异步线程安全

async def get_redis_pool():
    global _redis_pool
    if _redis_pool is None:
        async with _lock:
            if _redis_pool is None:
                _redis_pool = await aioredis.from_url(
                    settings.REDIS_URL,
                    encoding="utf8",
                    decode_responses=True,
                )
    return _redis_pool
